<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>linkdialog.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_editor_linkdialog.js.html">linkdialog.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview A dialog for editing/creating a link.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.ui.editor.LinkDialog&#39;);
<a name="line21"></a>goog.provide(&#39;goog.ui.editor.LinkDialog.BeforeTestLinkEvent&#39;);
<a name="line22"></a>goog.provide(&#39;goog.ui.editor.LinkDialog.EventType&#39;);
<a name="line23"></a>goog.provide(&#39;goog.ui.editor.LinkDialog.OkEvent&#39;);
<a name="line24"></a>
<a name="line25"></a>goog.require(&#39;goog.dom&#39;);
<a name="line26"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line27"></a>goog.require(&#39;goog.editor.BrowserFeature&#39;);
<a name="line28"></a>goog.require(&#39;goog.editor.Link&#39;);
<a name="line29"></a>goog.require(&#39;goog.editor.focus&#39;);
<a name="line30"></a>goog.require(&#39;goog.editor.node&#39;);
<a name="line31"></a>goog.require(&#39;goog.events.Event&#39;);
<a name="line32"></a>goog.require(&#39;goog.events.EventHandler&#39;);
<a name="line33"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line34"></a>goog.require(&#39;goog.events.InputHandler&#39;);
<a name="line35"></a>goog.require(&#39;goog.string&#39;);
<a name="line36"></a>goog.require(&#39;goog.style&#39;);
<a name="line37"></a>goog.require(&#39;goog.ui.Button&#39;);
<a name="line38"></a>goog.require(&#39;goog.ui.Component&#39;);
<a name="line39"></a>goog.require(&#39;goog.ui.LinkButtonRenderer&#39;);
<a name="line40"></a>goog.require(&#39;goog.ui.editor.AbstractDialog&#39;);
<a name="line41"></a>goog.require(&#39;goog.ui.editor.TabPane&#39;);
<a name="line42"></a>goog.require(&#39;goog.ui.editor.messages&#39;);
<a name="line43"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line44"></a>goog.require(&#39;goog.window&#39;);
<a name="line45"></a>
<a name="line46"></a>
<a name="line47"></a>
<a name="line48"></a>/**
<a name="line49"></a> * A type of goog.ui.editor.AbstractDialog for editing/creating a link.
<a name="line50"></a> * @param {goog.dom.DomHelper} domHelper DomHelper to be used to create the
<a name="line51"></a> *     dialog&#39;s dom structure.
<a name="line52"></a> * @param {goog.editor.Link} link The target link.
<a name="line53"></a> * @constructor
<a name="line54"></a> * @extends {goog.ui.editor.AbstractDialog}
<a name="line55"></a> */
<a name="line56"></a>goog.ui.editor.LinkDialog = function(domHelper, link) {
<a name="line57"></a>  goog.base(this, domHelper);
<a name="line58"></a>  this.targetLink_ = link;
<a name="line59"></a>
<a name="line60"></a>  /**
<a name="line61"></a>   * The event handler for this dialog.
<a name="line62"></a>   * @type {goog.events.EventHandler}
<a name="line63"></a>   * @private
<a name="line64"></a>   */
<a name="line65"></a>  this.eventHandler_ = new goog.events.EventHandler(this);
<a name="line66"></a>};
<a name="line67"></a>goog.inherits(goog.ui.editor.LinkDialog, goog.ui.editor.AbstractDialog);
<a name="line68"></a>
<a name="line69"></a>
<a name="line70"></a>/**
<a name="line71"></a> * Events specific to the link dialog.
<a name="line72"></a> * @enum {string}
<a name="line73"></a> */
<a name="line74"></a>goog.ui.editor.LinkDialog.EventType = {
<a name="line75"></a>  BEFORE_TEST_LINK: &#39;beforetestlink&#39;
<a name="line76"></a>};
<a name="line77"></a>
<a name="line78"></a>
<a name="line79"></a>
<a name="line80"></a>/**
<a name="line81"></a> * OK event object for the link dialog.
<a name="line82"></a> * @param {string} linkText Text the user chose to display for the link.
<a name="line83"></a> * @param {string} linkUrl Url the user chose for the link to point to.
<a name="line84"></a> * @param {boolean} openInNewWindow Whether the link should open in a new window
<a name="line85"></a> *     when clicked.
<a name="line86"></a> * @param {boolean} noFollow Whether the link should have &#39;rel=nofollow&#39;
<a name="line87"></a> *     attribute.
<a name="line88"></a> * @constructor
<a name="line89"></a> * @extends {goog.events.Event}
<a name="line90"></a> */
<a name="line91"></a>goog.ui.editor.LinkDialog.OkEvent = function(
<a name="line92"></a>    linkText, linkUrl, openInNewWindow, noFollow) {
<a name="line93"></a>  goog.base(this, goog.ui.editor.AbstractDialog.EventType.OK);
<a name="line94"></a>
<a name="line95"></a>  /**
<a name="line96"></a>   * The text of the link edited in the dialog.
<a name="line97"></a>   * @type {string}
<a name="line98"></a>   */
<a name="line99"></a>  this.linkText = linkText;
<a name="line100"></a>
<a name="line101"></a>  /**
<a name="line102"></a>   * The url of the link edited in the dialog.
<a name="line103"></a>   * @type {string}
<a name="line104"></a>   */
<a name="line105"></a>  this.linkUrl = linkUrl;
<a name="line106"></a>
<a name="line107"></a>  /**
<a name="line108"></a>   * Whether the link should open in a new window when clicked.
<a name="line109"></a>   * @type {boolean}
<a name="line110"></a>   */
<a name="line111"></a>  this.openInNewWindow = openInNewWindow;
<a name="line112"></a>
<a name="line113"></a>  /**
<a name="line114"></a>   * Whether the link should have &#39;rel=nofollow&#39; attribute.
<a name="line115"></a>   * @type {boolean}
<a name="line116"></a>   */
<a name="line117"></a>  this.noFollow = noFollow;
<a name="line118"></a>};
<a name="line119"></a>goog.inherits(goog.ui.editor.LinkDialog.OkEvent, goog.events.Event);
<a name="line120"></a>
<a name="line121"></a>
<a name="line122"></a>
<a name="line123"></a>/**
<a name="line124"></a> * Event fired before testing a link by opening it in another window.
<a name="line125"></a> * Calling preventDefault will stop the link from being opened.
<a name="line126"></a> * @param {string} url Url of the link being tested.
<a name="line127"></a> * @constructor
<a name="line128"></a> * @extends {goog.events.Event}
<a name="line129"></a> */
<a name="line130"></a>goog.ui.editor.LinkDialog.BeforeTestLinkEvent = function(url) {
<a name="line131"></a>  goog.base(this, goog.ui.editor.LinkDialog.EventType.BEFORE_TEST_LINK);
<a name="line132"></a>
<a name="line133"></a>  /**
<a name="line134"></a>   * The url of the link being tested.
<a name="line135"></a>   * @type {string}
<a name="line136"></a>   */
<a name="line137"></a>  this.url = url;
<a name="line138"></a>};
<a name="line139"></a>goog.inherits(goog.ui.editor.LinkDialog.BeforeTestLinkEvent, goog.events.Event);
<a name="line140"></a>
<a name="line141"></a>
<a name="line142"></a>/**
<a name="line143"></a> * Optional warning to show about email addresses.
<a name="line144"></a> * @type {string|undefined}
<a name="line145"></a> * @private
<a name="line146"></a> */
<a name="line147"></a>goog.ui.editor.LinkDialog.prototype.emailWarning_;
<a name="line148"></a>
<a name="line149"></a>
<a name="line150"></a>/**
<a name="line151"></a> * Whether to show a checkbox where the user can choose to have the link open in
<a name="line152"></a> * a new window.
<a name="line153"></a> * @type {boolean}
<a name="line154"></a> * @private
<a name="line155"></a> */
<a name="line156"></a>goog.ui.editor.LinkDialog.prototype.showOpenLinkInNewWindow_ = false;
<a name="line157"></a>
<a name="line158"></a>
<a name="line159"></a>/**
<a name="line160"></a> * Whether the &quot;open link in new window&quot; checkbox should be checked when the
<a name="line161"></a> * dialog is shown, and also whether it was checked last time the dialog was
<a name="line162"></a> * closed.
<a name="line163"></a> * @type {boolean}
<a name="line164"></a> * @private
<a name="line165"></a> */
<a name="line166"></a>goog.ui.editor.LinkDialog.prototype.isOpenLinkInNewWindowChecked_ = false;
<a name="line167"></a>
<a name="line168"></a>
<a name="line169"></a>/**
<a name="line170"></a> * Whether to show a checkbox where the user can choose to have &#39;rel=nofollow&#39;
<a name="line171"></a> * attribute added to the link.
<a name="line172"></a> * @type {boolean}
<a name="line173"></a> * @private
<a name="line174"></a> */
<a name="line175"></a>goog.ui.editor.LinkDialog.prototype.showRelNoFollow_ = false;
<a name="line176"></a>
<a name="line177"></a>
<a name="line178"></a>/**
<a name="line179"></a> * Sets the warning message to show to users about including email addresses on
<a name="line180"></a> * public web pages.
<a name="line181"></a> * @param {string} emailWarning Warning message to show users about including
<a name="line182"></a> *     email addresses on the web.
<a name="line183"></a> */
<a name="line184"></a>goog.ui.editor.LinkDialog.prototype.setEmailWarning = function(
<a name="line185"></a>    emailWarning) {
<a name="line186"></a>  this.emailWarning_ = emailWarning;
<a name="line187"></a>};
<a name="line188"></a>
<a name="line189"></a>
<a name="line190"></a>/**
<a name="line191"></a> * Tells the dialog to show a checkbox where the user can choose to have the
<a name="line192"></a> * link open in a new window.
<a name="line193"></a> * @param {boolean} startChecked Whether to check the checkbox the first
<a name="line194"></a> *     time the dialog is shown. Subesquent times the checkbox will remember its
<a name="line195"></a> *     previous state.
<a name="line196"></a> */
<a name="line197"></a>goog.ui.editor.LinkDialog.prototype.showOpenLinkInNewWindow = function(
<a name="line198"></a>    startChecked) {
<a name="line199"></a>  this.showOpenLinkInNewWindow_ = true;
<a name="line200"></a>  this.isOpenLinkInNewWindowChecked_ = startChecked;
<a name="line201"></a>};
<a name="line202"></a>
<a name="line203"></a>
<a name="line204"></a>/**
<a name="line205"></a> * Tells the dialog to show a checkbox where the user can choose to add
<a name="line206"></a> * &#39;rel=nofollow&#39; attribute to the link.
<a name="line207"></a> */
<a name="line208"></a>goog.ui.editor.LinkDialog.prototype.showRelNoFollow = function() {
<a name="line209"></a>  this.showRelNoFollow_ = true;
<a name="line210"></a>};
<a name="line211"></a>
<a name="line212"></a>
<a name="line213"></a>/** @override */
<a name="line214"></a>goog.ui.editor.LinkDialog.prototype.show = function() {
<a name="line215"></a>  goog.base(this, &#39;show&#39;);
<a name="line216"></a>
<a name="line217"></a>
<a name="line218"></a>  this.selectAppropriateTab_(this.textToDisplayInput_.value,
<a name="line219"></a>                             this.getTargetUrl_());
<a name="line220"></a>  this.syncOkButton_();
<a name="line221"></a>
<a name="line222"></a>  if (this.showOpenLinkInNewWindow_) {
<a name="line223"></a>    if (!this.targetLink_.isNew()) {
<a name="line224"></a>      // If link is not new, checkbox should reflect current target.
<a name="line225"></a>      this.isOpenLinkInNewWindowChecked_ =
<a name="line226"></a>          this.targetLink_.getAnchor().target == &#39;_blank&#39;;
<a name="line227"></a>    }
<a name="line228"></a>    this.openInNewWindowCheckbox_.checked = this.isOpenLinkInNewWindowChecked_;
<a name="line229"></a>  }
<a name="line230"></a>
<a name="line231"></a>  if (this.showRelNoFollow_) {
<a name="line232"></a>    this.relNoFollowCheckbox_.checked =
<a name="line233"></a>        goog.ui.editor.LinkDialog.hasNoFollow(this.targetLink_.getAnchor().rel);
<a name="line234"></a>  }
<a name="line235"></a>};
<a name="line236"></a>
<a name="line237"></a>
<a name="line238"></a>/** @override */
<a name="line239"></a>goog.ui.editor.LinkDialog.prototype.hide = function() {
<a name="line240"></a>  this.disableAutogenFlag_(false);
<a name="line241"></a>  goog.base(this, &#39;hide&#39;);
<a name="line242"></a>};
<a name="line243"></a>
<a name="line244"></a>
<a name="line245"></a>/**
<a name="line246"></a> * Tells the dialog whether to show the &#39;text to display&#39; div.
<a name="line247"></a> * When the target element of the dialog is an image, there is no link text
<a name="line248"></a> * to modify. This function can be used for this kind of situations.
<a name="line249"></a> * @param {boolean} visible Whether to make &#39;text to display&#39; div visible.
<a name="line250"></a> */
<a name="line251"></a>goog.ui.editor.LinkDialog.prototype.setTextToDisplayVisible = function(
<a name="line252"></a>    visible) {
<a name="line253"></a>  if (this.textToDisplayDiv_) {
<a name="line254"></a>    goog.style.setStyle(this.textToDisplayDiv_, &#39;display&#39;,
<a name="line255"></a>                        visible ? &#39;block&#39; : &#39;none&#39;);
<a name="line256"></a>  }
<a name="line257"></a>};
<a name="line258"></a>
<a name="line259"></a>
<a name="line260"></a>/**
<a name="line261"></a> * Tells the plugin whether to stop leaking the page&#39;s url via the referrer
<a name="line262"></a> * header when the &quot;test this link&quot; link is clicked.
<a name="line263"></a> * @param {boolean} stop Whether to stop leaking the referrer.
<a name="line264"></a> */
<a name="line265"></a>goog.ui.editor.LinkDialog.prototype.setStopReferrerLeaks = function(stop) {
<a name="line266"></a>  this.stopReferrerLeaks_ = stop;
<a name="line267"></a>};
<a name="line268"></a>
<a name="line269"></a>
<a name="line270"></a>/**
<a name="line271"></a> * Tells the dialog whether the autogeneration of text to display is to be
<a name="line272"></a> * enabled.
<a name="line273"></a> * @param {boolean} enable Whether to enable the feature.
<a name="line274"></a> */
<a name="line275"></a>goog.ui.editor.LinkDialog.prototype.setAutogenFeatureEnabled = function(
<a name="line276"></a>    enable) {
<a name="line277"></a>  this.autogenFeatureEnabled_ = enable;
<a name="line278"></a>};
<a name="line279"></a>
<a name="line280"></a>
<a name="line281"></a>/**
<a name="line282"></a> * Checks if {@code str} contains {@code &quot;nofollow&quot;} as a separate word.
<a name="line283"></a> * @param {string} str String to be tested.  This is usually {@code rel}
<a name="line284"></a> *     attribute of an {@code HTMLAnchorElement} object.
<a name="line285"></a> * @return {boolean} {@code true} if {@code str} contains {@code nofollow}.
<a name="line286"></a> */
<a name="line287"></a>goog.ui.editor.LinkDialog.hasNoFollow = function(str) {
<a name="line288"></a>  return goog.ui.editor.LinkDialog.NO_FOLLOW_REGEX_.test(str);
<a name="line289"></a>};
<a name="line290"></a>
<a name="line291"></a>
<a name="line292"></a>/**
<a name="line293"></a> * Removes {@code &quot;nofollow&quot;} from {@code rel} if it&#39;s present as a separate
<a name="line294"></a> * word.
<a name="line295"></a> * @param {string} rel Input string.  This is usually {@code rel} attribute of
<a name="line296"></a> *     an {@code HTMLAnchorElement} object.
<a name="line297"></a> * @return {string} {@code rel} with any {@code &quot;nofollow&quot;} removed.
<a name="line298"></a> */
<a name="line299"></a>goog.ui.editor.LinkDialog.removeNoFollow = function(rel) {
<a name="line300"></a>  return rel.replace(goog.ui.editor.LinkDialog.NO_FOLLOW_REGEX_, &#39;&#39;);
<a name="line301"></a>};
<a name="line302"></a>
<a name="line303"></a>
<a name="line304"></a>// *** Protected interface ************************************************** //
<a name="line305"></a>
<a name="line306"></a>
<a name="line307"></a>/** @override */
<a name="line308"></a>goog.ui.editor.LinkDialog.prototype.createDialogControl = function() {
<a name="line309"></a>  var builder = new goog.ui.editor.AbstractDialog.Builder(this);
<a name="line310"></a>  builder.setTitle(goog.ui.editor.messages.MSG_EDIT_LINK)
<a name="line311"></a>      .setContent(this.createDialogContent_());
<a name="line312"></a>  return builder.build();
<a name="line313"></a>};
<a name="line314"></a>
<a name="line315"></a>
<a name="line316"></a>/**
<a name="line317"></a> * Creates and returns the event object to be used when dispatching the OK
<a name="line318"></a> * event to listeners based on which tab is currently selected and the contents
<a name="line319"></a> * of the input fields of that tab.
<a name="line320"></a> * @return {goog.ui.editor.LinkDialog.OkEvent} The event object to be used when
<a name="line321"></a> *     dispatching the OK event to listeners.
<a name="line322"></a> * @protected
<a name="line323"></a> * @override
<a name="line324"></a> */
<a name="line325"></a>goog.ui.editor.LinkDialog.prototype.createOkEvent = function() {
<a name="line326"></a>  if (this.tabPane_.getCurrentTabId() ==
<a name="line327"></a>      goog.ui.editor.LinkDialog.Id_.EMAIL_ADDRESS_TAB) {
<a name="line328"></a>    return this.createOkEventFromEmailTab_();
<a name="line329"></a>  } else {
<a name="line330"></a>    return this.createOkEventFromWebTab_();
<a name="line331"></a>  }
<a name="line332"></a>};
<a name="line333"></a>
<a name="line334"></a>
<a name="line335"></a>/** @override */
<a name="line336"></a>goog.ui.editor.LinkDialog.prototype.disposeInternal = function() {
<a name="line337"></a>  this.eventHandler_.dispose();
<a name="line338"></a>  this.eventHandler_ = null;
<a name="line339"></a>
<a name="line340"></a>  this.tabPane_.dispose();
<a name="line341"></a>  this.tabPane_ = null;
<a name="line342"></a>
<a name="line343"></a>  this.urlInputHandler_.dispose();
<a name="line344"></a>  this.urlInputHandler_ = null;
<a name="line345"></a>  this.emailInputHandler_.dispose();
<a name="line346"></a>  this.emailInputHandler_ = null;
<a name="line347"></a>
<a name="line348"></a>  goog.base(this, &#39;disposeInternal&#39;);
<a name="line349"></a>};
<a name="line350"></a>
<a name="line351"></a>
<a name="line352"></a>// *** Private implementation *********************************************** //
<a name="line353"></a>
<a name="line354"></a>
<a name="line355"></a>/**
<a name="line356"></a> * Regular expression that matches {@code nofollow} value in an
<a name="line357"></a> * {@code * HTMLAnchorElement}&#39;s {@code rel} element.
<a name="line358"></a> * @type {RegExp}
<a name="line359"></a> * @private
<a name="line360"></a> */
<a name="line361"></a>goog.ui.editor.LinkDialog.NO_FOLLOW_REGEX_ = /\bnofollow\b/i;
<a name="line362"></a>
<a name="line363"></a>
<a name="line364"></a>/**
<a name="line365"></a> * The link being modified by this dialog.
<a name="line366"></a> * @type {goog.editor.Link}
<a name="line367"></a> * @private
<a name="line368"></a> */
<a name="line369"></a>goog.ui.editor.LinkDialog.prototype.targetLink_;
<a name="line370"></a>
<a name="line371"></a>
<a name="line372"></a>/**
<a name="line373"></a> * EventHandler object that keeps track of all handlers set by this dialog.
<a name="line374"></a> * @type {goog.events.EventHandler}
<a name="line375"></a> * @private
<a name="line376"></a> */
<a name="line377"></a>goog.ui.editor.LinkDialog.prototype.eventHandler_;
<a name="line378"></a>
<a name="line379"></a>
<a name="line380"></a>/**
<a name="line381"></a> * InputHandler object to listen for changes in the url input field.
<a name="line382"></a> * @type {goog.events.InputHandler}
<a name="line383"></a> * @private
<a name="line384"></a> */
<a name="line385"></a>goog.ui.editor.LinkDialog.prototype.urlInputHandler_;
<a name="line386"></a>
<a name="line387"></a>
<a name="line388"></a>/**
<a name="line389"></a> * InputHandler object to listen for changes in the email input field.
<a name="line390"></a> * @type {goog.events.InputHandler}
<a name="line391"></a> * @private
<a name="line392"></a> */
<a name="line393"></a>goog.ui.editor.LinkDialog.prototype.emailInputHandler_;
<a name="line394"></a>
<a name="line395"></a>
<a name="line396"></a>/**
<a name="line397"></a> * The tab bar where the url and email tabs are.
<a name="line398"></a> * @type {goog.ui.editor.TabPane}
<a name="line399"></a> * @private
<a name="line400"></a> */
<a name="line401"></a>goog.ui.editor.LinkDialog.prototype.tabPane_;
<a name="line402"></a>
<a name="line403"></a>
<a name="line404"></a>/**
<a name="line405"></a> * The div element holding the link&#39;s display text input.
<a name="line406"></a> * @type {HTMLDivElement}
<a name="line407"></a> * @private
<a name="line408"></a> */
<a name="line409"></a>goog.ui.editor.LinkDialog.prototype.textToDisplayDiv_;
<a name="line410"></a>
<a name="line411"></a>
<a name="line412"></a>/**
<a name="line413"></a> * The input element holding the link&#39;s display text.
<a name="line414"></a> * @type {HTMLInputElement}
<a name="line415"></a> * @private
<a name="line416"></a> */
<a name="line417"></a>goog.ui.editor.LinkDialog.prototype.textToDisplayInput_;
<a name="line418"></a>
<a name="line419"></a>
<a name="line420"></a>/**
<a name="line421"></a> * Whether or not the feature of automatically generating the display text is
<a name="line422"></a> * enabled.
<a name="line423"></a> * @type {boolean}
<a name="line424"></a> * @private
<a name="line425"></a> */
<a name="line426"></a>goog.ui.editor.LinkDialog.prototype.autogenFeatureEnabled_ = true;
<a name="line427"></a>
<a name="line428"></a>
<a name="line429"></a>/**
<a name="line430"></a> * Whether or not we should automatically generate the display text.
<a name="line431"></a> * @type {boolean}
<a name="line432"></a> * @private
<a name="line433"></a> */
<a name="line434"></a>goog.ui.editor.LinkDialog.prototype.autogenerateTextToDisplay_;
<a name="line435"></a>
<a name="line436"></a>
<a name="line437"></a>/**
<a name="line438"></a> * Whether or not automatic generation of the display text is disabled.
<a name="line439"></a> * @type {boolean}
<a name="line440"></a> * @private
<a name="line441"></a> */
<a name="line442"></a>goog.ui.editor.LinkDialog.prototype.disableAutogen_;
<a name="line443"></a>
<a name="line444"></a>
<a name="line445"></a>/**
<a name="line446"></a> * The input element (checkbox) to indicate that the link should open in a new
<a name="line447"></a> * window.
<a name="line448"></a> * @type {HTMLInputElement}
<a name="line449"></a> * @private
<a name="line450"></a> */
<a name="line451"></a>goog.ui.editor.LinkDialog.prototype.openInNewWindowCheckbox_;
<a name="line452"></a>
<a name="line453"></a>
<a name="line454"></a>/**
<a name="line455"></a> * The input element (checkbox) to indicate that the link should have
<a name="line456"></a> * &#39;rel=nofollow&#39; attribute.
<a name="line457"></a> * @type {HTMLInputElement}
<a name="line458"></a> * @private
<a name="line459"></a> */
<a name="line460"></a>goog.ui.editor.LinkDialog.prototype.relNoFollowCheckbox_;
<a name="line461"></a>
<a name="line462"></a>
<a name="line463"></a>/**
<a name="line464"></a> * Whether to stop leaking the page&#39;s url via the referrer header when the
<a name="line465"></a> * &quot;test this link&quot; link is clicked.
<a name="line466"></a> * @type {boolean}
<a name="line467"></a> * @private
<a name="line468"></a> */
<a name="line469"></a>goog.ui.editor.LinkDialog.prototype.stopReferrerLeaks_ = false;
<a name="line470"></a>
<a name="line471"></a>
<a name="line472"></a>/**
<a name="line473"></a> * Creates contents of this dialog.
<a name="line474"></a> * @return {Element} Contents of the dialog as a DOM element.
<a name="line475"></a> * @private
<a name="line476"></a> */
<a name="line477"></a>goog.ui.editor.LinkDialog.prototype.createDialogContent_ = function() {
<a name="line478"></a>  this.textToDisplayDiv_ = /** @type {HTMLDivElement} */(
<a name="line479"></a>      this.buildTextToDisplayDiv_());
<a name="line480"></a>  var content = this.dom.createDom(goog.dom.TagName.DIV, null,
<a name="line481"></a>      this.textToDisplayDiv_);
<a name="line482"></a>
<a name="line483"></a>  this.tabPane_ = new goog.ui.editor.TabPane(this.dom,
<a name="line484"></a>      goog.ui.editor.messages.MSG_LINK_TO);
<a name="line485"></a>  this.tabPane_.addTab(goog.ui.editor.LinkDialog.Id_.ON_WEB_TAB,
<a name="line486"></a>      goog.ui.editor.messages.MSG_ON_THE_WEB,
<a name="line487"></a>      goog.ui.editor.messages.MSG_ON_THE_WEB_TIP,
<a name="line488"></a>      goog.ui.editor.LinkDialog.BUTTON_GROUP_,
<a name="line489"></a>      this.buildTabOnTheWeb_());
<a name="line490"></a>  this.tabPane_.addTab(goog.ui.editor.LinkDialog.Id_.EMAIL_ADDRESS_TAB,
<a name="line491"></a>      goog.ui.editor.messages.MSG_EMAIL_ADDRESS,
<a name="line492"></a>      goog.ui.editor.messages.MSG_EMAIL_ADDRESS_TIP,
<a name="line493"></a>      goog.ui.editor.LinkDialog.BUTTON_GROUP_,
<a name="line494"></a>      this.buildTabEmailAddress_());
<a name="line495"></a>  this.tabPane_.render(content);
<a name="line496"></a>
<a name="line497"></a>  this.eventHandler_.listen(this.tabPane_, goog.ui.Component.EventType.SELECT,
<a name="line498"></a>      this.onChangeTab_);
<a name="line499"></a>
<a name="line500"></a>  if (this.showOpenLinkInNewWindow_) {
<a name="line501"></a>    content.appendChild(this.buildOpenInNewWindowDiv_());
<a name="line502"></a>  }
<a name="line503"></a>  if (this.showRelNoFollow_) {
<a name="line504"></a>    content.appendChild(this.buildRelNoFollowDiv_());
<a name="line505"></a>  }
<a name="line506"></a>
<a name="line507"></a>  return content;
<a name="line508"></a>};
<a name="line509"></a>
<a name="line510"></a>
<a name="line511"></a>/**
<a name="line512"></a> * Builds and returns the text to display section of the edit link dialog.
<a name="line513"></a> * @return {Element} A div element to be appended into the dialog div.
<a name="line514"></a> * @private
<a name="line515"></a> */
<a name="line516"></a>goog.ui.editor.LinkDialog.prototype.buildTextToDisplayDiv_ = function() {
<a name="line517"></a>  var table = this.dom.createTable(1, 2);
<a name="line518"></a>  table.cellSpacing = &#39;0&#39;;
<a name="line519"></a>  table.cellPadding = &#39;0&#39;;
<a name="line520"></a>  table.style.fontSize = &#39;10pt&#39;;
<a name="line521"></a>  // Build the text to display input.
<a name="line522"></a>  var textToDisplayDiv = this.dom.createDom(goog.dom.TagName.DIV);
<a name="line523"></a>  table.rows[0].cells[0].innerHTML = &#39;&lt;span style=&quot;position: relative;&#39; +
<a name="line524"></a>      &#39; bottom: 2px; padding-right: 1px; white-space: nowrap;&quot;&gt;&#39; +
<a name="line525"></a>      goog.ui.editor.messages.MSG_TEXT_TO_DISPLAY + &#39;&amp;nbsp;&lt;/span&gt;&#39;;
<a name="line526"></a>  this.textToDisplayInput_ = /** @type {HTMLInputElement} */(
<a name="line527"></a>      this.dom.createDom(goog.dom.TagName.INPUT,
<a name="line528"></a>          {id: goog.ui.editor.LinkDialog.Id_.TEXT_TO_DISPLAY}));
<a name="line529"></a>  var textInput = this.textToDisplayInput_;
<a name="line530"></a>  // 98% prevents scroll bars in standards mode.
<a name="line531"></a>  // TODO(robbyw): Is this necessary for quirks mode?
<a name="line532"></a>  goog.style.setStyle(textInput, &#39;width&#39;, &#39;98%&#39;);
<a name="line533"></a>  goog.style.setStyle(table.rows[0].cells[1], &#39;width&#39;, &#39;100%&#39;);
<a name="line534"></a>  goog.dom.appendChild(table.rows[0].cells[1], textInput);
<a name="line535"></a>
<a name="line536"></a>  textInput.value = this.targetLink_.getCurrentText();
<a name="line537"></a>  this.eventHandler_.listen(textInput,
<a name="line538"></a>                            goog.events.EventType.KEYUP,
<a name="line539"></a>                            goog.bind(this.onTextToDisplayEdit_, this));
<a name="line540"></a>
<a name="line541"></a>  goog.dom.appendChild(textToDisplayDiv, table);
<a name="line542"></a>  return textToDisplayDiv;
<a name="line543"></a>};
<a name="line544"></a>
<a name="line545"></a>
<a name="line546"></a>/**
<a name="line547"></a> * Builds and returns the &quot;checkbox to open the link in a new window&quot; section of
<a name="line548"></a> * the edit link dialog.
<a name="line549"></a> * @return {Element} A div element to be appended into the dialog div.
<a name="line550"></a> * @private
<a name="line551"></a> */
<a name="line552"></a>goog.ui.editor.LinkDialog.prototype.buildOpenInNewWindowDiv_ = function() {
<a name="line553"></a>  this.openInNewWindowCheckbox_ = /** @type {HTMLInputElement} */(
<a name="line554"></a>      this.dom.createDom(goog.dom.TagName.INPUT, {&#39;type&#39;: &#39;checkbox&#39;}));
<a name="line555"></a>  return this.dom.createDom(goog.dom.TagName.DIV, null,
<a name="line556"></a>      this.dom.createDom(goog.dom.TagName.LABEL, null,
<a name="line557"></a>                         this.openInNewWindowCheckbox_,
<a name="line558"></a>                         goog.ui.editor.messages.MSG_OPEN_IN_NEW_WINDOW));
<a name="line559"></a>};
<a name="line560"></a>
<a name="line561"></a>
<a name="line562"></a>/**
<a name="line563"></a> * Creates a DIV with a checkbox for {@code rel=nofollow} option.
<a name="line564"></a> * @return {Element} Newly created DIV element.
<a name="line565"></a> * @private
<a name="line566"></a> */
<a name="line567"></a>goog.ui.editor.LinkDialog.prototype.buildRelNoFollowDiv_ = function() {
<a name="line568"></a>  /** @desc Checkbox text for adding &#39;rel=nofollow&#39; attribute to a link. */
<a name="line569"></a>  var MSG_ADD_REL_NOFOLLOW_ATTR = goog.getMsg(
<a name="line570"></a>      &quot;Add &#39;{$relNoFollow}&#39; attribute ({$linkStart}Learn more{$linkEnd})&quot;, {
<a name="line571"></a>        &#39;relNoFollow&#39;: &#39;rel=nofollow&#39;,
<a name="line572"></a>        &#39;linkStart&#39;: &#39;&lt;a href=&quot;http://support.google.com/webmasters/bin/&#39; +
<a name="line573"></a>            &#39;answer.py?hl=en&amp;answer=96569&quot; target=&quot;_blank&quot;&gt;&#39;,
<a name="line574"></a>        &#39;linkEnd&#39;: &#39;&lt;/a&gt;&#39;
<a name="line575"></a>      });
<a name="line576"></a>
<a name="line577"></a>  this.relNoFollowCheckbox_ = /** @type {HTMLInputElement} */(
<a name="line578"></a>      this.dom.createDom(goog.dom.TagName.INPUT, {&#39;type&#39;: &#39;checkbox&#39;}));
<a name="line579"></a>  return this.dom.createDom(goog.dom.TagName.DIV, null,
<a name="line580"></a>      this.dom.createDom(goog.dom.TagName.LABEL, null,
<a name="line581"></a>          this.relNoFollowCheckbox_,
<a name="line582"></a>          goog.dom.htmlToDocumentFragment(MSG_ADD_REL_NOFOLLOW_ATTR)));
<a name="line583"></a>};
<a name="line584"></a>
<a name="line585"></a>
<a name="line586"></a>/**
<a name="line587"></a>* Builds and returns the div containing the tab &quot;On the web&quot;.
<a name="line588"></a>* @return {Element} The div element containing the tab.
<a name="line589"></a>* @private
<a name="line590"></a>*/
<a name="line591"></a>goog.ui.editor.LinkDialog.prototype.buildTabOnTheWeb_ = function() {
<a name="line592"></a>  var onTheWebDiv = this.dom.createElement(goog.dom.TagName.DIV);
<a name="line593"></a>
<a name="line594"></a>  var headingDiv = this.dom.createDom(goog.dom.TagName.DIV,
<a name="line595"></a>      {innerHTML: &#39;&lt;b&gt;&#39; + goog.ui.editor.messages.MSG_WHAT_URL + &#39;&lt;/b&gt;&#39;});
<a name="line596"></a>  var urlInput = this.dom.createDom(goog.dom.TagName.INPUT,
<a name="line597"></a>      {
<a name="line598"></a>        id: goog.ui.editor.LinkDialog.Id_.ON_WEB_INPUT,
<a name="line599"></a>        className: goog.ui.editor.LinkDialog.TARGET_INPUT_CLASSNAME_
<a name="line600"></a>      });
<a name="line601"></a>  // IE throws on unknown values for type.
<a name="line602"></a>  if (!goog.userAgent.IE) {
<a name="line603"></a>    // On browsers that support Web Forms 2.0, allow autocompletion of URLs.
<a name="line604"></a>    // (As of now, this is only supported by Opera 9)
<a name="line605"></a>    urlInput.type = &#39;url&#39;;
<a name="line606"></a>  }
<a name="line607"></a>
<a name="line608"></a>  if (goog.editor.BrowserFeature.NEEDS_99_WIDTH_IN_STANDARDS_MODE &amp;&amp;
<a name="line609"></a>      goog.editor.node.isStandardsMode(urlInput)) {
<a name="line610"></a>    urlInput.style.width = &#39;99%&#39;;
<a name="line611"></a>  }
<a name="line612"></a>
<a name="line613"></a>  var inputDiv = this.dom.createDom(goog.dom.TagName.DIV, null, urlInput);
<a name="line614"></a>
<a name="line615"></a>  this.urlInputHandler_ = new goog.events.InputHandler(urlInput);
<a name="line616"></a>  this.eventHandler_.listen(this.urlInputHandler_,
<a name="line617"></a>      goog.events.InputHandler.EventType.INPUT,
<a name="line618"></a>      this.onUrlOrEmailInputChange_);
<a name="line619"></a>
<a name="line620"></a>  var testLink = new goog.ui.Button(goog.ui.editor.messages.MSG_TEST_THIS_LINK,
<a name="line621"></a>      goog.ui.LinkButtonRenderer.getInstance(),
<a name="line622"></a>      this.dom);
<a name="line623"></a>  testLink.render(inputDiv);
<a name="line624"></a>  testLink.getElement().style.marginTop = &#39;1em&#39;;
<a name="line625"></a>  this.eventHandler_.listen(testLink,
<a name="line626"></a>      goog.ui.Component.EventType.ACTION,
<a name="line627"></a>      this.onWebTestLink_);
<a name="line628"></a>
<a name="line629"></a>  // Build the &quot;On the web&quot; explanation text div.
<a name="line630"></a>  var explanationDiv = this.dom.createDom(goog.dom.TagName.DIV,
<a name="line631"></a>      {
<a name="line632"></a>        className: goog.ui.editor.LinkDialog.EXPLANATION_TEXT_CLASSNAME_,
<a name="line633"></a>        innerHTML: goog.ui.editor.messages.MSG_TR_LINK_EXPLANATION
<a name="line634"></a>      });
<a name="line635"></a>  onTheWebDiv.appendChild(headingDiv);
<a name="line636"></a>  onTheWebDiv.appendChild(inputDiv);
<a name="line637"></a>  onTheWebDiv.appendChild(explanationDiv);
<a name="line638"></a>
<a name="line639"></a>  return onTheWebDiv;
<a name="line640"></a>};
<a name="line641"></a>
<a name="line642"></a>
<a name="line643"></a>/**
<a name="line644"></a> * Builds and returns the div containing the tab &quot;Email address&quot;.
<a name="line645"></a> * @return {Element} the div element containing the tab.
<a name="line646"></a> * @private
<a name="line647"></a> */
<a name="line648"></a>goog.ui.editor.LinkDialog.prototype.buildTabEmailAddress_ = function() {
<a name="line649"></a>  var emailTab = this.dom.createDom(goog.dom.TagName.DIV);
<a name="line650"></a>
<a name="line651"></a>  var headingDiv = this.dom.createDom(goog.dom.TagName.DIV,
<a name="line652"></a>      {innerHTML: &#39;&lt;b&gt;&#39; + goog.ui.editor.messages.MSG_WHAT_EMAIL + &#39;&lt;/b&gt;&#39;});
<a name="line653"></a>  goog.dom.appendChild(emailTab, headingDiv);
<a name="line654"></a>  var emailInput = this.dom.createDom(goog.dom.TagName.INPUT,
<a name="line655"></a>      {
<a name="line656"></a>        id: goog.ui.editor.LinkDialog.Id_.EMAIL_ADDRESS_INPUT,
<a name="line657"></a>        className: goog.ui.editor.LinkDialog.TARGET_INPUT_CLASSNAME_
<a name="line658"></a>      });
<a name="line659"></a>
<a name="line660"></a>  if (goog.editor.BrowserFeature.NEEDS_99_WIDTH_IN_STANDARDS_MODE &amp;&amp;
<a name="line661"></a>      goog.editor.node.isStandardsMode(emailInput)) {
<a name="line662"></a>    // Standards mode sizes this too large.
<a name="line663"></a>    emailInput.style.width = &#39;99%&#39;;
<a name="line664"></a>  }
<a name="line665"></a>
<a name="line666"></a>  goog.dom.appendChild(emailTab, emailInput);
<a name="line667"></a>
<a name="line668"></a>  this.emailInputHandler_ = new goog.events.InputHandler(emailInput);
<a name="line669"></a>  this.eventHandler_.listen(this.emailInputHandler_,
<a name="line670"></a>      goog.events.InputHandler.EventType.INPUT,
<a name="line671"></a>      this.onUrlOrEmailInputChange_);
<a name="line672"></a>
<a name="line673"></a>  goog.dom.appendChild(emailTab,
<a name="line674"></a>      this.dom.createDom(goog.dom.TagName.DIV,
<a name="line675"></a>          {
<a name="line676"></a>            id: goog.ui.editor.LinkDialog.Id_.EMAIL_WARNING,
<a name="line677"></a>            className: goog.ui.editor.LinkDialog.EMAIL_WARNING_CLASSNAME_,
<a name="line678"></a>            style: &#39;visibility:hidden&#39;
<a name="line679"></a>          }, goog.ui.editor.messages.MSG_INVALID_EMAIL));
<a name="line680"></a>
<a name="line681"></a>  if (this.emailWarning_) {
<a name="line682"></a>    var explanationDiv = this.dom.createDom(goog.dom.TagName.DIV,
<a name="line683"></a>        {
<a name="line684"></a>          className: goog.ui.editor.LinkDialog.EXPLANATION_TEXT_CLASSNAME_,
<a name="line685"></a>          innerHTML: this.emailWarning_
<a name="line686"></a>        });
<a name="line687"></a>    goog.dom.appendChild(emailTab, explanationDiv);
<a name="line688"></a>  }
<a name="line689"></a>  return emailTab;
<a name="line690"></a>};
<a name="line691"></a>
<a name="line692"></a>
<a name="line693"></a>/**
<a name="line694"></a> * Returns the url that the target points to.
<a name="line695"></a> * @return {string} The url that the target points to.
<a name="line696"></a> * @private
<a name="line697"></a> */
<a name="line698"></a>goog.ui.editor.LinkDialog.prototype.getTargetUrl_ = function() {
<a name="line699"></a>  // Get the href-attribute through getAttribute() rather than the href property
<a name="line700"></a>  // because Google-Toolbar on Firefox with &quot;Send with Gmail&quot; turned on
<a name="line701"></a>  // modifies the href-property of &#39;mailto:&#39; links but leaves the attribute
<a name="line702"></a>  // untouched.
<a name="line703"></a>  return this.targetLink_.getAnchor().getAttribute(&#39;href&#39;) || &#39;&#39;;
<a name="line704"></a>};
<a name="line705"></a>
<a name="line706"></a>
<a name="line707"></a>/**
<a name="line708"></a> * Selects the correct tab based on the URL, and fills in its inputs.
<a name="line709"></a> * For new links, it suggests a url based on the link text.
<a name="line710"></a> * @param {string} text The inner text of the link.
<a name="line711"></a> * @param {string} url The href for the link.
<a name="line712"></a> * @private
<a name="line713"></a> */
<a name="line714"></a>goog.ui.editor.LinkDialog.prototype.selectAppropriateTab_ = function(
<a name="line715"></a>    text, url) {
<a name="line716"></a>  if (this.isNewLink_()) {
<a name="line717"></a>    // Newly created non-empty link: try to infer URL from the link text.
<a name="line718"></a>    this.guessUrlAndSelectTab_(text);
<a name="line719"></a>  } else if (goog.editor.Link.isMailto(url)) {
<a name="line720"></a>    // The link is for an email.
<a name="line721"></a>    this.tabPane_.setSelectedTabId(
<a name="line722"></a>        goog.ui.editor.LinkDialog.Id_.EMAIL_ADDRESS_TAB);
<a name="line723"></a>    this.dom.getElement(goog.ui.editor.LinkDialog.Id_.EMAIL_ADDRESS_INPUT)
<a name="line724"></a>        .value = url.substring(url.indexOf(&#39;:&#39;) + 1);
<a name="line725"></a>    this.setAutogenFlagFromCurInput_();
<a name="line726"></a>  } else {
<a name="line727"></a>    // No specific tab was appropriate, default to on the web tab.
<a name="line728"></a>    this.tabPane_.setSelectedTabId(goog.ui.editor.LinkDialog.Id_.ON_WEB_TAB);
<a name="line729"></a>    this.dom.getElement(goog.ui.editor.LinkDialog.Id_.ON_WEB_INPUT)
<a name="line730"></a>        .value = this.isNewLink_() ? &#39;http://&#39; : url;
<a name="line731"></a>    this.setAutogenFlagFromCurInput_();
<a name="line732"></a>  }
<a name="line733"></a>};
<a name="line734"></a>
<a name="line735"></a>
<a name="line736"></a>/**
<a name="line737"></a> * Select a url/tab based on the link&#39;s text. This function is simply
<a name="line738"></a> * the isNewLink_() == true case of selectAppropriateTab_().
<a name="line739"></a> * @param {string} text The inner text of the link.
<a name="line740"></a> * @private
<a name="line741"></a> */
<a name="line742"></a>goog.ui.editor.LinkDialog.prototype.guessUrlAndSelectTab_ = function(text) {
<a name="line743"></a>  if (goog.editor.Link.isLikelyEmailAddress(text)) {
<a name="line744"></a>    // The text is for an email address.
<a name="line745"></a>    this.tabPane_.setSelectedTabId(
<a name="line746"></a>        goog.ui.editor.LinkDialog.Id_.EMAIL_ADDRESS_TAB);
<a name="line747"></a>    this.dom.getElement(goog.ui.editor.LinkDialog.Id_.EMAIL_ADDRESS_INPUT)
<a name="line748"></a>        .value = text;
<a name="line749"></a>    this.setAutogenFlag_(true);
<a name="line750"></a>    // TODO(user): Why disable right after enabling? What bug are we
<a name="line751"></a>    // working around?
<a name="line752"></a>    this.disableAutogenFlag_(true);
<a name="line753"></a>  } else if (goog.editor.Link.isLikelyUrl(text)) {
<a name="line754"></a>    // The text is for a web URL.
<a name="line755"></a>    this.tabPane_.setSelectedTabId(goog.ui.editor.LinkDialog.Id_.ON_WEB_TAB);
<a name="line756"></a>    this.dom.getElement(goog.ui.editor.LinkDialog.Id_.ON_WEB_INPUT)
<a name="line757"></a>        .value = text;
<a name="line758"></a>    this.setAutogenFlag_(true);
<a name="line759"></a>    this.disableAutogenFlag_(true);
<a name="line760"></a>  } else {
<a name="line761"></a>    // No meaning could be deduced from text, choose a default tab.
<a name="line762"></a>    if (!this.targetLink_.getCurrentText()) {
<a name="line763"></a>      this.setAutogenFlag_(true);
<a name="line764"></a>    }
<a name="line765"></a>    this.tabPane_.setSelectedTabId(goog.ui.editor.LinkDialog.Id_.ON_WEB_TAB);
<a name="line766"></a>  }
<a name="line767"></a>};
<a name="line768"></a>
<a name="line769"></a>
<a name="line770"></a>/**
<a name="line771"></a> * Called on a change to the url or email input. If either one of those tabs
<a name="line772"></a> * is active, sets the OK button to enabled/disabled accordingly.
<a name="line773"></a> * @private
<a name="line774"></a> */
<a name="line775"></a>goog.ui.editor.LinkDialog.prototype.syncOkButton_ = function() {
<a name="line776"></a>  var inputValue;
<a name="line777"></a>  if (this.tabPane_.getCurrentTabId() ==
<a name="line778"></a>      goog.ui.editor.LinkDialog.Id_.EMAIL_ADDRESS_TAB) {
<a name="line779"></a>    inputValue = this.dom.getElement(
<a name="line780"></a>        goog.ui.editor.LinkDialog.Id_.EMAIL_ADDRESS_INPUT).value;
<a name="line781"></a>    this.toggleInvalidEmailWarning_(inputValue != &#39;&#39; &amp;&amp;
<a name="line782"></a>        !goog.editor.Link.isLikelyEmailAddress(inputValue));
<a name="line783"></a>  } else if (this.tabPane_.getCurrentTabId() ==
<a name="line784"></a>      goog.ui.editor.LinkDialog.Id_.ON_WEB_TAB) {
<a name="line785"></a>    inputValue = this.dom.getElement(
<a name="line786"></a>        goog.ui.editor.LinkDialog.Id_.ON_WEB_INPUT).value;
<a name="line787"></a>  } else {
<a name="line788"></a>    return;
<a name="line789"></a>  }
<a name="line790"></a>  this.getOkButtonElement().disabled = goog.string.isEmpty(inputValue);
<a name="line791"></a>};
<a name="line792"></a>
<a name="line793"></a>
<a name="line794"></a>/**
<a name="line795"></a> * Show/hide the Invalid Email Address warning.
<a name="line796"></a> * @param {boolean} on Whether to show the warning.
<a name="line797"></a> * @private
<a name="line798"></a> */
<a name="line799"></a>goog.ui.editor.LinkDialog.prototype.toggleInvalidEmailWarning_ = function(on) {
<a name="line800"></a>  this.dom.getElement(goog.ui.editor.LinkDialog.Id_.EMAIL_WARNING)
<a name="line801"></a>      .style.visibility = (on ? &#39;visible&#39; : &#39;hidden&#39;);
<a name="line802"></a>};
<a name="line803"></a>
<a name="line804"></a>
<a name="line805"></a>/**
<a name="line806"></a> * Changes the autogenerateTextToDisplay flag so that text to
<a name="line807"></a> * display stops autogenerating.
<a name="line808"></a> * @private
<a name="line809"></a> */
<a name="line810"></a>goog.ui.editor.LinkDialog.prototype.onTextToDisplayEdit_ = function() {
<a name="line811"></a>  var inputEmpty = this.textToDisplayInput_.value == &#39;&#39;;
<a name="line812"></a>  if (inputEmpty) {
<a name="line813"></a>    this.setAutogenFlag_(true);
<a name="line814"></a>  } else {
<a name="line815"></a>    this.setAutogenFlagFromCurInput_();
<a name="line816"></a>  }
<a name="line817"></a>};
<a name="line818"></a>
<a name="line819"></a>
<a name="line820"></a>/**
<a name="line821"></a> * The function called when hitting OK with the &quot;On the web&quot; tab current.
<a name="line822"></a> * @return {goog.ui.editor.LinkDialog.OkEvent} The event object to be used when
<a name="line823"></a> *     dispatching the OK event to listeners.
<a name="line824"></a> * @private
<a name="line825"></a> */
<a name="line826"></a>goog.ui.editor.LinkDialog.prototype.createOkEventFromWebTab_ = function() {
<a name="line827"></a>  var input = /** @type {HTMLInputElement} */(
<a name="line828"></a>      this.dom.getElement(goog.ui.editor.LinkDialog.Id_.ON_WEB_INPUT));
<a name="line829"></a>  var linkURL = input.value;
<a name="line830"></a>  if (goog.editor.Link.isLikelyEmailAddress(linkURL)) {
<a name="line831"></a>    // Make sure that if user types in an e-mail address, it becomes &quot;mailto:&quot;.
<a name="line832"></a>    return this.createOkEventFromEmailTab_(
<a name="line833"></a>        goog.ui.editor.LinkDialog.Id_.ON_WEB_INPUT);
<a name="line834"></a>  } else {
<a name="line835"></a>    if (linkURL.search(/:/) &lt; 0) {
<a name="line836"></a>      linkURL = &#39;http://&#39; + goog.string.trimLeft(linkURL);
<a name="line837"></a>    }
<a name="line838"></a>    return this.createOkEventFromUrl_(linkURL);
<a name="line839"></a>  }
<a name="line840"></a>};
<a name="line841"></a>
<a name="line842"></a>
<a name="line843"></a>/**
<a name="line844"></a> * The function called when hitting OK with the &quot;email address&quot; tab current.
<a name="line845"></a> * @param {string=} opt_inputId Id of an alternate input to check.
<a name="line846"></a> * @return {goog.ui.editor.LinkDialog.OkEvent} The event object to be used when
<a name="line847"></a> *     dispatching the OK event to listeners.
<a name="line848"></a> * @private
<a name="line849"></a> */
<a name="line850"></a>goog.ui.editor.LinkDialog.prototype.createOkEventFromEmailTab_ = function(
<a name="line851"></a>    opt_inputId) {
<a name="line852"></a>  var linkURL = this.dom.getElement(
<a name="line853"></a>      opt_inputId || goog.ui.editor.LinkDialog.Id_.EMAIL_ADDRESS_INPUT).value;
<a name="line854"></a>  linkURL = &#39;mailto:&#39; + linkURL;
<a name="line855"></a>  return this.createOkEventFromUrl_(linkURL);
<a name="line856"></a>};
<a name="line857"></a>
<a name="line858"></a>
<a name="line859"></a>/**
<a name="line860"></a> * Function to test a link from the on the web tab.
<a name="line861"></a> * @private
<a name="line862"></a> */
<a name="line863"></a>goog.ui.editor.LinkDialog.prototype.onWebTestLink_ = function() {
<a name="line864"></a>  var input = /** @type {HTMLInputElement} */(
<a name="line865"></a>      this.dom.getElement(goog.ui.editor.LinkDialog.Id_.ON_WEB_INPUT));
<a name="line866"></a>  var url = input.value;
<a name="line867"></a>  if (url.search(/:/) &lt; 0) {
<a name="line868"></a>    url = &#39;http://&#39; + goog.string.trimLeft(url);
<a name="line869"></a>  }
<a name="line870"></a>  if (this.dispatchEvent(
<a name="line871"></a>      new goog.ui.editor.LinkDialog.BeforeTestLinkEvent(url))) {
<a name="line872"></a>    var win = this.dom.getWindow();
<a name="line873"></a>    var size = goog.dom.getViewportSize(win);
<a name="line874"></a>    var openOptions = {
<a name="line875"></a>      target: &#39;_blank&#39;,
<a name="line876"></a>      width: Math.max(size.width - 50, 50),
<a name="line877"></a>      height: Math.max(size.height - 50, 50),
<a name="line878"></a>      toolbar: true,
<a name="line879"></a>      scrollbars: true,
<a name="line880"></a>      location: true,
<a name="line881"></a>      statusbar: false,
<a name="line882"></a>      menubar: true,
<a name="line883"></a>      &#39;resizable&#39;: true,
<a name="line884"></a>      &#39;noreferrer&#39;: this.stopReferrerLeaks_
<a name="line885"></a>    };
<a name="line886"></a>    goog.window.open(url, openOptions, win);
<a name="line887"></a>  }
<a name="line888"></a>};
<a name="line889"></a>
<a name="line890"></a>
<a name="line891"></a>/**
<a name="line892"></a> * Called whenever the url or email input is edited. If the text to display
<a name="line893"></a> * matches the text to display, turn on auto. Otherwise if auto is on, update
<a name="line894"></a> * the text to display based on the url.
<a name="line895"></a> * @private
<a name="line896"></a> */
<a name="line897"></a>goog.ui.editor.LinkDialog.prototype.onUrlOrEmailInputChange_ = function() {
<a name="line898"></a>  if (this.autogenerateTextToDisplay_) {
<a name="line899"></a>    this.setTextToDisplayFromAuto_();
<a name="line900"></a>  } else if (this.textToDisplayInput_.value == &#39;&#39;) {
<a name="line901"></a>    this.setAutogenFlagFromCurInput_();
<a name="line902"></a>  }
<a name="line903"></a>  this.syncOkButton_();
<a name="line904"></a>};
<a name="line905"></a>
<a name="line906"></a>
<a name="line907"></a>/**
<a name="line908"></a> * Called when the currently selected tab changes.
<a name="line909"></a> * @param {goog.events.Event} e The tab change event.
<a name="line910"></a> * @private
<a name="line911"></a> */
<a name="line912"></a>goog.ui.editor.LinkDialog.prototype.onChangeTab_ = function(e) {
<a name="line913"></a>  var tab = /** @type {goog.ui.Tab} */ (e.target);
<a name="line914"></a>
<a name="line915"></a>  // Focus on the input field in the selected tab.
<a name="line916"></a>  var input = this.dom.getElement(tab.getId() +
<a name="line917"></a>      goog.ui.editor.LinkDialog.Id_.TAB_INPUT_SUFFIX);
<a name="line918"></a>  goog.editor.focus.focusInputField(input);
<a name="line919"></a>
<a name="line920"></a>  // For some reason, IE does not fire onpropertychange events when the width
<a name="line921"></a>  // is specified as a percentage, which breaks the InputHandlers.
<a name="line922"></a>  input.style.width = &#39;&#39;;
<a name="line923"></a>  input.style.width = input.offsetWidth + &#39;px&#39;;
<a name="line924"></a>
<a name="line925"></a>  this.syncOkButton_();
<a name="line926"></a>  this.setTextToDisplayFromAuto_();
<a name="line927"></a>};
<a name="line928"></a>
<a name="line929"></a>
<a name="line930"></a>/**
<a name="line931"></a> * If autogen is turned on, set the value of text to display based on the
<a name="line932"></a> * current selection or url.
<a name="line933"></a> * @private
<a name="line934"></a> */
<a name="line935"></a>goog.ui.editor.LinkDialog.prototype.setTextToDisplayFromAuto_ = function() {
<a name="line936"></a>  if (this.autogenFeatureEnabled_ &amp;&amp; this.autogenerateTextToDisplay_) {
<a name="line937"></a>    var inputId = this.tabPane_.getCurrentTabId() +
<a name="line938"></a>        goog.ui.editor.LinkDialog.Id_.TAB_INPUT_SUFFIX;
<a name="line939"></a>    this.textToDisplayInput_.value =
<a name="line940"></a>        /** @type {HTMLInputElement} */(this.dom.getElement(inputId)).value;
<a name="line941"></a>  }
<a name="line942"></a>};
<a name="line943"></a>
<a name="line944"></a>
<a name="line945"></a>/**
<a name="line946"></a> * Turn on the autogenerate text to display flag, and set some sort of indicator
<a name="line947"></a> * that autogen is on.
<a name="line948"></a> * @param {boolean} val Boolean value to set autogenerate to.
<a name="line949"></a> * @private
<a name="line950"></a> */
<a name="line951"></a>goog.ui.editor.LinkDialog.prototype.setAutogenFlag_ = function(val) {
<a name="line952"></a>  // TODO(user): This whole autogen thing is very confusing. It needs
<a name="line953"></a>  // to be refactored and/or explained.
<a name="line954"></a>  this.autogenerateTextToDisplay_ = val;
<a name="line955"></a>};
<a name="line956"></a>
<a name="line957"></a>
<a name="line958"></a>/**
<a name="line959"></a> * Disables autogen so that onUrlOrEmailInputChange_ doesn&#39;t act in cases
<a name="line960"></a> * that are undesirable.
<a name="line961"></a> * @param {boolean} autogen Boolean value to set disableAutogen to.
<a name="line962"></a> * @private
<a name="line963"></a> */
<a name="line964"></a>goog.ui.editor.LinkDialog.prototype.disableAutogenFlag_ = function(autogen) {
<a name="line965"></a>  this.setAutogenFlag_(!autogen);
<a name="line966"></a>  this.disableAutogen_ = autogen;
<a name="line967"></a>};
<a name="line968"></a>
<a name="line969"></a>
<a name="line970"></a>/**
<a name="line971"></a> * Creates an OK event from the text to display input and the specified link.
<a name="line972"></a> * If text to display input is empty, then generate the auto value for it.
<a name="line973"></a> * @return {goog.ui.editor.LinkDialog.OkEvent} The event object to be used when
<a name="line974"></a> *     dispatching the OK event to listeners.
<a name="line975"></a> * @param {string} url Url the target element should point to.
<a name="line976"></a> * @private
<a name="line977"></a> */
<a name="line978"></a>goog.ui.editor.LinkDialog.prototype.createOkEventFromUrl_ = function(url) {
<a name="line979"></a>  // Fill in the text to display input in case it is empty.
<a name="line980"></a>  this.setTextToDisplayFromAuto_();
<a name="line981"></a>  if (this.showOpenLinkInNewWindow_) {
<a name="line982"></a>    // Save checkbox state for next time.
<a name="line983"></a>    this.isOpenLinkInNewWindowChecked_ = this.openInNewWindowCheckbox_.checked;
<a name="line984"></a>  }
<a name="line985"></a>  return new goog.ui.editor.LinkDialog.OkEvent(this.textToDisplayInput_.value,
<a name="line986"></a>      url, this.showOpenLinkInNewWindow_ &amp;&amp; this.isOpenLinkInNewWindowChecked_,
<a name="line987"></a>      this.showRelNoFollow_ &amp;&amp; this.relNoFollowCheckbox_.checked);
<a name="line988"></a>};
<a name="line989"></a>
<a name="line990"></a>
<a name="line991"></a>/**
<a name="line992"></a> * If an email or url is being edited, set autogenerate to on if the text to
<a name="line993"></a> * display matches the url.
<a name="line994"></a> * @private
<a name="line995"></a> */
<a name="line996"></a>goog.ui.editor.LinkDialog.prototype.setAutogenFlagFromCurInput_ = function() {
<a name="line997"></a>  var autogen = false;
<a name="line998"></a>  if (!this.disableAutogen_) {
<a name="line999"></a>    var tabInput = this.dom.getElement(this.tabPane_.getCurrentTabId() +
<a name="line1000"></a>        goog.ui.editor.LinkDialog.Id_.TAB_INPUT_SUFFIX);
<a name="line1001"></a>    autogen = (tabInput.value == this.textToDisplayInput_.value);
<a name="line1002"></a>  }
<a name="line1003"></a>  this.setAutogenFlag_(autogen);
<a name="line1004"></a>};
<a name="line1005"></a>
<a name="line1006"></a>
<a name="line1007"></a>/**
<a name="line1008"></a> * @return {boolean} Whether the link is new.
<a name="line1009"></a> * @private
<a name="line1010"></a> */
<a name="line1011"></a>goog.ui.editor.LinkDialog.prototype.isNewLink_ = function() {
<a name="line1012"></a>  return this.targetLink_.isNew();
<a name="line1013"></a>};
<a name="line1014"></a>
<a name="line1015"></a>
<a name="line1016"></a>/**
<a name="line1017"></a> * IDs for relevant DOM elements.
<a name="line1018"></a> * @enum {string}
<a name="line1019"></a> * @private
<a name="line1020"></a> */
<a name="line1021"></a>goog.ui.editor.LinkDialog.Id_ = {
<a name="line1022"></a>  TEXT_TO_DISPLAY: &#39;linkdialog-text&#39;,
<a name="line1023"></a>  ON_WEB_TAB: &#39;linkdialog-onweb&#39;,
<a name="line1024"></a>  ON_WEB_INPUT: &#39;linkdialog-onweb-tab-input&#39;,
<a name="line1025"></a>  EMAIL_ADDRESS_TAB: &#39;linkdialog-email&#39;,
<a name="line1026"></a>  EMAIL_ADDRESS_INPUT: &#39;linkdialog-email-tab-input&#39;,
<a name="line1027"></a>  EMAIL_WARNING: &#39;linkdialog-email-warning&#39;,
<a name="line1028"></a>  TAB_INPUT_SUFFIX: &#39;-tab-input&#39;
<a name="line1029"></a>};
<a name="line1030"></a>
<a name="line1031"></a>
<a name="line1032"></a>/**
<a name="line1033"></a> * Base name for the radio buttons group.
<a name="line1034"></a> * @type {string}
<a name="line1035"></a> * @private
<a name="line1036"></a> */
<a name="line1037"></a>goog.ui.editor.LinkDialog.BUTTON_GROUP_ = &#39;linkdialog-buttons&#39;;
<a name="line1038"></a>
<a name="line1039"></a>
<a name="line1040"></a>/**
<a name="line1041"></a> * Class name for the url and email input elements.
<a name="line1042"></a> * @type {string}
<a name="line1043"></a> * @private
<a name="line1044"></a> */
<a name="line1045"></a>goog.ui.editor.LinkDialog.TARGET_INPUT_CLASSNAME_ =
<a name="line1046"></a>    goog.getCssName(&#39;tr-link-dialog-target-input&#39;);
<a name="line1047"></a>
<a name="line1048"></a>
<a name="line1049"></a>/**
<a name="line1050"></a> * Class name for the email address warning element.
<a name="line1051"></a> * @type {string}
<a name="line1052"></a> * @private
<a name="line1053"></a> */
<a name="line1054"></a>goog.ui.editor.LinkDialog.EMAIL_WARNING_CLASSNAME_ =
<a name="line1055"></a>    goog.getCssName(&#39;tr-link-dialog-email-warning&#39;);
<a name="line1056"></a>
<a name="line1057"></a>
<a name="line1058"></a>/**
<a name="line1059"></a> * Class name for the explanation text elements.
<a name="line1060"></a> * @type {string}
<a name="line1061"></a> * @private
<a name="line1062"></a> */
<a name="line1063"></a>goog.ui.editor.LinkDialog.EXPLANATION_TEXT_CLASSNAME_ =
<a name="line1064"></a>    goog.getCssName(&#39;tr-link-dialog-explanation-text&#39;);
</pre>


</body>
</html>
